Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpk cloud get namespaces/clusters #1322

Merged
merged 10 commits into from
May 7, 2021

Conversation

alenkacz
Copy link
Contributor

@alenkacz alenkacz commented May 3, 2021

Cover letter

Adds cloud get namespaces and cloud get clusters commands.

rpk cloud get namespaces
  ID                                    NAME    CLUSTERS
  ef32e76b-0e23-4a44-893d-c3db5192d2b1  andres  1
  398a22d9-b086-4da5-8e64-154e16ae241f  ring0   1

rpk cloud get clusters
Error: please provide --namespace flag

rpk cloud get clusters -n ring0
  ID                                    NAME  READY
  564ecbd8-ca39-4dce-90cb-a6e6bffae9d3  TEST  true

Release notes

If the PR changes the user experience, write a short summary of the changes. See the CONTRIBUTING guidelines for details.

Release note: [1-2 sentences of what this PR changes]

@alenkacz alenkacz changed the title Av/rpk cloud get rpk cloud get namespaces/clusters May 3, 2021
@emaxerrno
Copy link
Contributor

wow this is fire!

src/go/rpk/pkg/vcloud/yak/client.go Outdated Show resolved Hide resolved
src/go/rpk/pkg/vcloud/yak/client.go Show resolved Hide resolved
src/go/rpk/pkg/vcloud/yak/client.go Outdated Show resolved Hide resolved
src/go/rpk/pkg/vcloud/yak/client.go Outdated Show resolved Hide resolved
src/go/rpk/pkg/vcloud/yak/client.go Outdated Show resolved Hide resolved
src/go/rpk/pkg/vcloud/yak/api.go Show resolved Hide resolved
src/go/rpk/pkg/vcloud/yak/client.go Outdated Show resolved Hide resolved
Comment on lines 70 to 122
func (yc *YakClient) get(token, url string) (*http.Response, error) {
log.Debugf("Calling yak api on url %s", url)
req, err := http.NewRequest(http.MethodGet, url, bytes.NewBuffer([]byte{}))
if err != nil {
return nil, fmt.Errorf("error creating new request. %w", err)
}
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
return http.DefaultClient.Do(req)
}

func (yc *YakClient) handleErrResponseCodes(
resp *http.Response, body []byte,
) error {
// targetting HTTP codes 401, 403 which are used by yak
if resp.StatusCode > 400 && resp.StatusCode < 404 {
log.Debug(string(body))
return ErrNotAuthorized
}
if resp.StatusCode != 200 {
return fmt.Errorf("error retrieving resource, http code %d. %s", resp.StatusCode, body)
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes should go in the 1st commit, where you introduced the YakClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree I was waiting until the second method to extract the code meaningfully and to be honest solving the merge conflicts makes me not want to do it. Do you feel strongly about doing that? :D

src/go/rpk/pkg/vcloud/yak/client.go Outdated Show resolved Hide resolved
src/go/rpk/pkg/cli/cmd/cloud/namespaces.go Show resolved Hide resolved
@alenkacz alenkacz force-pushed the av/rpk-cloud-get branch 2 times, most recently from 8438b8f to 4d80984 Compare May 4, 2021 13:52
src/go/rpk/pkg/vcloud/yak/client.go Outdated Show resolved Hide resolved

func NewNamespacesCommand(fs afero.Fs, out io.Writer) *cobra.Command {
return &cobra.Command{
Use: "namespaces",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the command. An alias for rpk cloud get namespaces, following the kubectl conventions would be rpk cloud get ns.
kubernetes/kubernetes#42873

src/go/rpk/pkg/cli/cmd/cloud/namespaces.go Show resolved Hide resolved
src/go/rpk/pkg/cli/cmd/cloud/namespaces_test.go Outdated Show resolved Hide resolved
@@ -45,33 +45,53 @@ func (yc *YakClient) GetNamespaces() ([]*Namespace, error) {
return nil, ErrLoginTokenMissing{err}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit could be squashed onto the 1st one, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm maybe, can we keep it like this thought? 🙏

src/go/rpk/pkg/cli/cmd/cloud/clusters_test.go Outdated Show resolved Hide resolved
0x5d
0x5d previously approved these changes May 5, 2021
Copy link
Contributor

@0x5d 0x5d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@0x5d
Copy link
Contributor

0x5d commented May 5, 2021

@alenkacz please rebase and let's merge this! 🎉

@mmaslankaprv mmaslankaprv merged commit 41a4f36 into redpanda-data:dev May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants